//
//  LZVideoDetialTitleAndStarCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/3.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZVideoDetialTitleAndStarCell.h"
#import "GiftListLabel.h"
#import "HCSStarRatingView.h"
#import "Masonry.h"

@interface LZVideoDetialTitleAndStarCell()
@property (weak, nonatomic) IBOutlet GiftListLabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *starBgView;
@property (nonatomic, strong) HCSStarRatingView *starRatingView;

@end

@implementation LZVideoDetialTitleAndStarCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.starBgView.backgroundColor = [UIColor clearColor];

    [self configureLabel];
    
    [self.starBgView addSubview:self.starRatingView];
    [self.starRatingView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.starBgView);
    }];
    // Initialization code
    
    self.titleLabel.font = [UIFont fontWithName:@"ArialMT" size:15];
}

- (UILabel*)getCellTitleLabel {
    return self.titleLabel;
}

- (void)loadTitle:(NSString *)titleStr StarCount:(CGFloat)starCount
{
    [self setTitleLabelText:titleStr];
    [self setStarViewWithLevel:starCount];
}

- (void)setTitleLabelText:(NSString *)text
{
    if (text.length > 0) {
        extern CGFloat textLineSpace;
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        
        [style setLineSpacing:textLineSpace];
        [style setLineBreakMode:NSLineBreakByWordWrapping];
        [style setAlignment:NSTextAlignmentNatural];
        
        [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
        self.titleLabel.attributedText = attStr;
    }
   
}

- (void)setStarViewWithLevel:(CGFloat)index
{
    self.starRatingView.value = index;
}

#pragma mark -
#pragma mark configure label
- (void)configureLabel
{
    [self.titleLabel setVerticalAlignment:VerticalAlignmentTop];
}

- (HCSStarRatingView *)starRatingView
{
    if (!_starRatingView) {
        _starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectZero];
        _starRatingView.maximumValue = 5;
        _starRatingView.minimumValue = 0;
        _starRatingView.spacing = 2.5;
        _starRatingView.allowsHalfStars = YES;
        _starRatingView.accurateHalfStars = YES;
        _starRatingView.tintColor = UIColorFromRGB(0xF08F4D, 1);
        _starRatingView.userInteractionEnabled = NO;
    }
    
    return _starRatingView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
